use tock_registers::{
    register_bitfields, register_structs,
    registers::{ReadOnly, ReadWrite, WriteOnly},
};

register_structs! {
    pub UartRegs {
        /// Data Register.
        (0x00 => pub  dr: ReadWrite<u32, DATA::Register>),
        (0x04 =>  _reserved0),
        /// Flag Register.
        (0x18 => pub fr: ReadOnly<u32, FLAG::Register>),
        (0x1c =>  _reserved1),
        ///
        (0x24 => pub tibd: ReadWrite<u32>),
        ///
        (0x28 => pub tfbd: ReadWrite<u32>),
        /// Control register.
        (0x2c => pub cr_h: ReadWrite<u32, CONTROLH::Register>),
        (0x30 => pub cr_l: ReadWrite<u32,CONTROLL::Register>),
        /// Interrupt FIFO Level Select Register.
        (0x34 => pub ifls: ReadWrite<u32>),
        /// Interrupt Mask Set Clear Register.
        (0x38 => pub imsc: ReadWrite<u32>),
        /// Raw Interrupt Status Register.
        (0x3c => pub ris: ReadOnly<u32>),
        /// Masked Interrupt Status Register.
        (0x40 => pub mis: ReadOnly<u32>),
        /// Interrupt Clear Register.
        (0x44 => pub icr: WriteOnly<u32>),
        (0x48 => @END),
    }
}

register_bitfields![u32,
    pub DATA [
        RAW OFFSET(0) NUMBITS(8),
        FE OFFSET(9) NUMBITS(1),
        PE OFFSET(10) NUMBITS(1),
        BE OFFSET(11) NUMBITS(1),
        OE OFFSET(12) NUMBITS(1),
    ],
    pub  FLAG [
        CTS OFFSET(0) NUMBITS(1),
        DSR OFFSET(1) NUMBITS(1),
        DCD OFFSET(2) NUMBITS(1),
        BUSY OFFSET(3) NUMBITS(1),
        RXFE OFFSET(4) NUMBITS(1),
        TXFF OFFSET(5) NUMBITS(1),
        RXFF OFFSET(6) NUMBITS(1),
        TXFE OFFSET(7) NUMBITS(1),
    ],
    pub CONTROLH [
        BRK OFFSET(0) NUMBITS(1) [],
        PEN OFFSET(1) NUMBITS(1) [],
        EPS OFFSET(2) NUMBITS(1) [],
        STP2 OFFSET(3) NUMBITS(1) [],
        FEN OFFSET(4) NUMBITS(1) [],
        WLEN OFFSET(5) NUMBITS(2) [
            len5 = 0,
            len6 = 1,
            len7 = 2,
            len8= 3
        ],
        SPS OFFSET(7) NUMBITS(1) [],
    ],
    pub CONTROLL [
        ENABLE OFFSET(0) NUMBITS(1) [],
        RSV OFFSET(1) NUMBITS(7) [],
        TXE OFFSET(8) NUMBITS(1) [],
        RXE OFFSET(9) NUMBITS(1) [],
    ],
];
